package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"user_srv/model"
	"user_srv/user_proto"
)

func (s *Server) GetUserList(ctx context.Context, in *user_proto.GetUserListRequest) (*user_proto.GetUserListResponse, error) {
	nums, list, err := model.UserList(int(in.Page), int(in.Limit))
	if err != nil {
		return nil, status.Error(codes.Internal, "获取列表失败")
	}
	var userList []*user_proto.UserInfo
	for _, v := range list {
		userList = append(userList, &user_proto.UserInfo{
			Id:       int64(v.ID),
			Mobile:   v.Mobile,
			Password: v.Password,
			NickName: v.NickName,
			BirthDay: v.BirthDay,
			Sex:      int64(v.Sex),
			Age:      int64(v.Age),
		})
	}
	return &user_proto.GetUserListResponse{Total: nums, UserInfo: userList}, nil
}
